@extends('admin.layout')

@section('content')

<body>
<form method="post" action="">
    <div class="panel admin-panel">
        <div class="panel-head"><strong class="icon-reorder"> 用户管理</strong></div>
        
        <table class="table table-hover text-center">
            <tr>
                <th width="5%">ID</th>
                <th width="20%">用户名</th>       
                <th width="25%">注册时间</th>
                <th width="25%">操作</th>       
            </tr>  
            
            @foreach($users as $user)
            <tr>
                <td>{{ $loop->iteration }}</td>
                <td>{{ $user->username }}</td>
                <td>{{ $user->created_at }}</td>
                <td>
                    <div class="button-group"> 
                        <a class="button {{$user->is_freeze ? 'border-red' : 'border-blue'}}" href="javascript:void(0)" onclick="freeze({{ $user->id }} , {{ $user->is_freeze }})">{{ $user->is_freeze ? '冻结' : '解冻'}}</a>
                    </div>
                </td>
            </tr>
            @endforeach
        
            <tr>
              <td colspan="8">{{ $users->links() }}</td>
            </tr>
        </table>
    </div>
</form>
<script type="text/javascript">
    function freeze(id , freeze) {

        var freeze = (freeze?'冻结？':'解冻？');
        var _token = "{{ csrf_token() }}";

        layer.confirm("您确定要"+freeze,function() {
            $.ajax({
                type:'delete',
                url:'/admin/freeze/'+id,
                datatype:'json',
                data:{_token:_token},
                success:function(res) {
                    if ( res.status == 'success' ) {
                        location.href="{{ url('admin/user') }}";
                    } else {
                        layer.msg(res.msg , {icon:2});
                    }
                }
            })
        })
    }
</script>
</body>

@endsection